package com.shanzhe.eshop.common.util;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author yinwei
 * @create 2021/9/30
 * @Version 1.0
 */
@Data
public class ResultBean<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private String code;
    private String msg;
    private Long date;
    private T data;

    public ResultBean(T data) {
        this.code = "000000";
        this.msg = "";
        this.date = System.currentTimeMillis();
        this.data = data;
    }

    public static ResultBean error(String errorMsg) {
        return new ResultBean("010101", errorMsg, System.currentTimeMillis(), (Object)null);
    }

    public static ResultBean error(String errorCode, String errorMsg) {
        return new ResultBean(errorCode, errorMsg, System.currentTimeMillis(), (Object)null);
    }

    public static ResultBean success(Object data) {
        return new ResultBean("000000", "成功", System.currentTimeMillis(), data);
    }


    public Boolean hasError() {
        return !"000000".equals(this.getCode());
    }

    public ResultBean(final String code, final String msg, final Long date, final T data) {
        this.code = code;
        this.msg = msg;
        this.date = date;
        this.data = data;
    }

}
